package com.co.view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.WindowConstants;

import com.co.controller.MainMenuPageController;
import com.co.utils.Constants;
import com.co.utils.ImagePanel;
import com.co.utils.JPage;
import com.co.utils.Logger;

/**
 * This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
 * Builder, which is free for non-commercial use. If Jigloo is being used
 * commercially (ie, by a corporation, company or business for any purpose
 * whatever) then you should purchase a license for each developer using Jigloo.
 * Please visit www.cloudgarden.com for details. Use of Jigloo implies
 * acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN
 * PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR
 * ANY CORPORATE OR COMMERCIAL PURPOSE.
 */
public class MainMenuPage extends JPage {
	private JMenuBar jMenuBar1;
	private JMenuItem jMenuItem2;
	private JMenuItem jMenuItem1;
	private JMenu jMenu1;
	private String title = "Inicio";
	private JMenu jMenu5;
	private JMenuItem jMenuItem3;
	private JMenuItem jMenuItem4;
	private ImagePanel image1;
	private JMenu jMenu4;
	private JMenu jMenu3;
	private JMenu jMenu2;

	// Controller
	private MainMenuPageController mainMenuPageController;

	// SINGLETON
	private static MainMenuPage mainMenuInstance;

	public static MainMenuPage getInstance() {
		if (mainMenuInstance == null) {
			mainMenuInstance = new MainMenuPage();
		}
		return mainMenuInstance;
	}

	// Constructor
	public MainMenuPage() {
		super();
		this.setId(Constants.MAIN_MENU_PAGE);

		// Inicializo el controlador.
		mainMenuPageController = MainMenuPageController.getInstance();
		mainMenuPageController.configure(this.getId(), this);

		initGUI();
	}

	private void initGUI() {
		try {
			{
			}
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			{

			}
			{
				jMenuBar1 = new JMenuBar();
				setJMenuBar(jMenuBar1);
				jMenuBar1.setPreferredSize(new java.awt.Dimension(384, 18));
				{
					jMenu1 = new JMenu();
					jMenuBar1.add(jMenu1);
					jMenu1.setText("Menu");
					{
						jMenuItem1 = new JMenuItem();
						jMenu1.add(jMenuItem1);
						jMenuItem1.setText("Paciente");
						jMenuItem1.addActionListener(new ActionListener() {
							public void actionPerformed(ActionEvent evt) {
								System.out
										.println("jMenuItem2.actionPerformed, event="
												+ evt);
								loadPacientePage();
							}
						});
					}
					{
						jMenuItem2 = new JMenuItem();
						jMenu1.add(jMenuItem2);
						jMenuItem2.setText("Salir");
						jMenuItem2.addActionListener(new ActionListener() {
							public void actionPerformed(ActionEvent evt) {
								System.out
										.println("jMenuItem2.actionPerformed, event="
												+ evt);
								System.exit(0);
							}
						});
					}
					{
						jMenuItem3 = new JMenuItem();
						jMenu1.add(jMenuItem3);
						jMenuItem3.setText("Prestaciones");
						jMenuItem3.addActionListener(new ActionListener() {
							public void actionPerformed(ActionEvent evt) {
								System.out
										.println("jMenuItem2.actionPerformed, event="
												+ evt);
								loadPrestacionesPage();
							}
						});
					}
					{
						jMenuItem4 = new JMenuItem();
						jMenu1.add(jMenuItem4);
						jMenuItem4.setText("Obra Social");
						jMenuItem4.addActionListener(new ActionListener() {
							public void actionPerformed(ActionEvent evt) {
								System.out
										.println("jMenuItem2.actionPerformed, event="
												+ evt);
								mainMenuPageController.goToObraSocialPage();

							}
						});
					}

				}
				{
					jMenu2 = new JMenu();
					jMenuBar1.add(jMenu2);
					jMenu2.setText("Paciente");
					jMenu2.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							System.out
									.println("jMenuItem2.actionPerformed, event="
											+ evt);
							loadPacientePage();
						}
					});
				}
				{
					jMenu3 = new JMenu();
					jMenuBar1.add(jMenu3);
					jMenu3.setText("Radiografia");
				}
				{
					jMenu4 = new JMenu();
					jMenuBar1.add(jMenu4);
					jMenu4.setText("Nomenclador");
				}
				{
					jMenu5 = new JMenu();
					jMenuBar1.add(jMenu5);
					jMenu5.setText("Utilidades");
				}
			}
			{
				image1 = new ImagePanel("//resources//Muelita.jpg");
				getContentPane().add(image1);
				image1.setBounds(80, 38, 60, 30);
				image1.setLocation(50, 50);
				image1.repaint();
			}
			pack();
			this.setTitle("Consultorios Odontologicos - " + this.title);
			this.setSize(1024, 332);
			this.setExtendedState(MAXIMIZED_BOTH);

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private void loadPacientePage() {
		Logger.showMessage("- loadPacientePage -");
		PacientePage pacientePage = PacientePage.getInstance();
		pacientePage.setVisible(true);

		MainMenuPage indexPage = MainMenuPage.getInstance();
		indexPage.setVisible(false);
	}

	private void loadPrestacionesPage() {
		Logger.showMessage("- loadPestacionesPage -");
		PrestacionesPage prestacionesPage = PrestacionesPage.getInstance();
		prestacionesPage.setVisible(true);

		MainMenuPage indexPage = MainMenuPage.getInstance();
		indexPage.setVisible(false);
	}

	/**
	 * This method should return an instance of this class which does NOT
	 * initialize it's GUI elements. This method is ONLY required by Jigloo if
	 * the superclass of this class is abstract or non-public. It is not needed
	 * in any other situation.
	 */
	public static Object getGUIBuilderInstance() {
		return new MainMenuPage(Boolean.FALSE);
	}

	/**
	 * This constructor is used by the getGUIBuilderInstance method to provide
	 * an instance of this class which has not had it's GUI elements initialized
	 * (ie, initGUI is not called in this constructor).
	 */
	public MainMenuPage(Boolean initGUI) {
		super();
	}

}
